class Solution {
public:
    int lengthOfLastWord(string s) {
        int n = s.size() - 1;

        while (s[n] == ' ')
        {
            n--;
        }
        int ret = 0;
        while (s[n--] != ' ')
        {
            ret++;
            if (n < 0)
                return ret; 

        }
        return ret;
    }
};